<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('门店编码')">
              <a-input :placeholder="$t('请输入门店编码')" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('门店名称')">
              <a-input :placeholder="$t('请输入门店名称')" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('状态')">
                <j-switch :placeholder="$t('请选择状态')" v-model="queryParam.state"  query></j-switch>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('负责人')">
                <a-input :placeholder="$t('请输入负责人')" v-model="queryParam.contact"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('负责人电话')">
                <a-input :placeholder="$t('请输入负责人电话')" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('系统类型')">
                <a-select v-model="queryParam.type" :placeholder="$t('请选择系统类型')">
                  <a-select-option v-for="item in typeList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('有效截止日期')">
                <a-date-picker
                  :show-time="false"
                  valueFormat="YYYY-MM-DD"
                  :placeholder="$t('请选择开始日期')"
                  class="query-group-cust"
                  v-model="queryParam.endDate_begin"
                ></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker
                  :show-time="false"
                  valueFormat="YYYY-MM-DD"
                  :placeholder="$t('请选择结束日期')"
                  class="query-group-cust"
                  v-model="queryParam.endDate_end"
                ></a-date-picker>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('卡店码')">
                <a-input :placeholder="$t('请输入卡店码')" v-model="queryParam.cardCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('门店类型')">
                <j-dict-select-tag :placeholder="$t('请选择')" v-model="queryParam.location" dictCode="bis_shop.location"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'ShopManageList:add'" type="primary" icon="plus">{{$t('新增')}}</a-button>
      <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('门店管理'))">{{$t('导出')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无图片')}}</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无文件')}}</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleSet(record)" v-has="'ShopManageList:settings'">{{$t('运营设置')}}</a>
          <a-divider type="vertical" v-has="'ShopManageList:settings'" />
          <a @click="handleEdit(record)" v-has="'ShopManageList:edit'">{{$t('编辑')}}</a>
          <a-divider type="vertical" v-has="'ShopManageList:edit'" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('更多')}} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">{{$t('详情')}}</a>
              </a-menu-item>
              <a-menu-item v-has="'ShopManageList:delete'">
                <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
                  <a>{{$t('删除')}}</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleShare(1,record)">{{$t('分享链接')}}</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleGiftEdit(record)">{{$t('商城接入')}}</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <shop-manage-modal ref="modalForm" @ok="modalFormOk"></shop-manage-modal>
    <shop-manage-gift-modal ref="giftModel" @ok="modalFormOk"></shop-manage-gift-modal>
    <shop-share-modal ref="modalShare"></shop-share-modal>
    <operational-param-settings-modal ref="optParamSet"></operational-param-settings-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ShopManageModal from './modules/ShopManageModal'
  import ShopShareModal from './modules/ShopShareModal'
  import ShopManageGiftModal from './modules/ShopManageGiftModal'
  import OperationalParamSettingsModal from './modules/OperationalParamSettingsModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { getAction } from '@/api/manage'

  export default {
    name: 'ShopManageList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ShopManageModal,
      ShopShareModal,
      ShopManageGiftModal,
      OperationalParamSettingsModal
    },
    data () {
      return {
        description: '门店管理管理页面',
        // 表头
        columns: [
          {
            title:this.$t('门店类型'),
            align:"center",
            sorter: true,
            dataIndex: 'location_dictText'
          },
          {
            title:this.$t('门店编码'),
            align:"center",
            sorter: true,
            dataIndex: 'code'
          },
          {
            title:this.$t('卡店码'),
            align:"center",
            sorter: true,
            dataIndex: 'cardCode'
          },
          {
            title:this.$t('门店名称'),
            align:"center",
            sorter: true,
            dataIndex: 'name'
          },
          {
            title:this.$t('系统类型'),
            align:"center",
            sorter: true,
            dataIndex: 'type_dictText'
          },
          {
            title:this.$t('原始主机号'),
            align:"center",
            sorter: true,
            dataIndex: 'hostId'
          },
          {
            title:this.$t('状态'),
            align:"center",
            dataIndex: 'state',
            customRender: (text) => (text ? filterMultiDictText(this.dictOptions['state'], text) : ''),
          },
          {
            title:this.$t('负责人'),
            align:"center",
            dataIndex: 'contact'
          },
          {
            title:this.$t('负责人电话'),
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:this.$t('门店地址'),
            align:"center",
            dataIndex: 'address'
          },
          {
            title:this.$t('备注'),
            align:"center",
            dataIndex: 'comment'
          },
          {
            title:this.$t('图片'),
            align:"center",
            dataIndex: 'shopPicture',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:this.$t('有效期'),
            align:"center",
            dataIndex: 'beginDate',
            customRender:(text,record)=>{
              return record.beginDate + '~' +record.endDate
            }
          },
          {
            title: this.$t('操作'),
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/shop/bisShop/list",
          delete: "/shop/bisShop/delete",
          deleteBatch: "/shop/bisShop/deleteBatch",
          exportXlsUrl: "/shop/bisShop/exportXls",
          importExcelUrl: "shop/bisShop/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        typeList:[],
      }
    },
    created() {
      this.$set(this.dictOptions, 'state', [{text:this.$t('是'),value:'Y'},{text:this.$t('否'),value:'N'}])
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
        getAction('/system/bisSysType/list',{pageNo: 1,pageSize: 999}).then(res=>{
          if(res.success){
            this.typeList = res.result.records
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:this.$t('门店编码'),dictCode:''})
        fieldList.push({type:'string',value:'cardCode',text:this.$t('卡店码'),dictCode:''})
        fieldList.push({type:'string',value:'name',text:this.$t('门店名称'),dictCode:''})
        fieldList.push({type:'switch',value:'state',text:this.$t('状态')})
        fieldList.push({type:'string',value:'contact',text:this.$t('联系人'),dictCode:''})
        fieldList.push({type:'string',value:'address',text:this.$t('门店地址'),dictCode:''})
        fieldList.push({type:'string',value:'comment',text:this.$t('备注'),dictCode:''})
        fieldList.push({type:'string',value:'shopPicture',text:this.$t('图片'),dictCode:''})
        this.superFieldList = fieldList
      },
      handleShare(type,record){
        this.$refs.modalShare.edit(type,record)
      },
      handleGiftEdit(record){
        this.$refs.giftModel.edit(record)
      },
      handleSet(record){
        this.$refs.optParamSet.edit(record)
        this.$refs.optParamSet.disableSubmit = false
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>